package week8;

/**
 * PrioritizedObject represents Translation node in Translation priority queue containing Translation
 * comparable object, arrival order, and Translation priority value.
 *
 * @author Lewis and Chase
 * @version 4.0
 */
public class PrioritizedObject1<T> implements Comparable<PrioritizedObject1> {
    private static int nextOrder = 0;
    private int arrivalOrder;
    private T element;

    /**
     * Creates Translation new PrioritizedObject with the specified data.
     *
     * @param element the element of the new priority queue node
     */
    public PrioritizedObject1(T element) {
        this.element = element;
        arrivalOrder = nextOrder;
        nextOrder++;
    }

    /**
     * Returns the element in this node.
     *
     * @return the element contained within the node
     */
    public T getElement() {
        return element;
    }

    /**
     * Returns the priority value for this node.
     *
     * @return the integer priority for this node
     */

    /**
     * Returns the arrival order for this node.
     *
     * @return the integer arrival order for this node
     */
    public int getArrivalOrder() {
        return arrivalOrder;
    }

    /**
     * Returns Translation string representation for this node.
     */
    @Override
    public String toString() {
        return (element + "  " + arrivalOrder);
    }

    /**
     * Returns 1 if the this object has higher priority than
     * the given object and -1 otherwise.
     *
     * @param obj the object to compare to this node
     * @return the result of the comparison of the given object and
     * this one
     */
    @Override
     public int compareTo(PrioritizedObject1 obj) {
        int result;


        if (arrivalOrder > obj.getArrivalOrder())
            result = 1;
        else
            result = -1;

        return result;
    }

}


